home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 476-500 / disk_478 / mp / mp.doc < prev    next >
Text File  |  1992-05-06  |  16KB  |  472 lines

  1. MP:        A MIDI Playground
  2. Author:        Daniel J. Barrett, barrett@cs.jhu.edu.
  3. No Copyright:    100% Public Domain.
  4.         Please share this program with others.
  5.  
  6. Requirements:    A Commodore Amiga.
  7. Optional:    A MIDI Interface on your serial port.
  8.         1 or more MIDI instruments.
  9.         (Without MIDI, this program is not very useful, except
  10.          perhaps as a source code example for serial port
  11.          programming and parsing input.)
  12.  
  13. Legal stuff:    Use this program entirely at your own risk.  The author
  14.         bears no responsibility for any damage or data loss you
  15.         may incur through the use or misuse of this program.
  16.  
  17.     
  18. GETTING QUICK HELP
  19.  
  20.     At the command line, type:
  21.  
  22.         1>  mp ?
  23.  
  24. TABLE OF CONTENTS
  25.  
  26. Line    Section
  27. ===========================================================================
  28.  18    Getting quick help
  29.  24    Table of contents
  30.  46    What is MP?
  31.  77    What is MP not?
  32.  84    MP concepts
  33. 118    A first exercise
  34. 132    Formal usage instructions for MP
  35. 162    The input text language
  36. 237    Practicing with the text language
  37. 264    Using the file input/output options to make new windows
  38. 277    Using redirection
  39. 306    Translating binary data to/from text
  40. 318    Using an alternate MIDI interface
  41. 359    Problems you may have with MP
  42. 425    Notes about the source code
  43. 457    Notes about the program's internals (and limitations)
  44.     
  45.     
  46. WHAT IS MP?
  47.  
  48.     Have you ever wanted to see what MIDI data your instrument is
  49. transmitting?  Have you ever wanted to send your own MIDI data to your
  50. MIDI instrument?  Then MP is for you!!
  51.  
  52.     MP (MIDI Playground) is a versatile tool for sending, receiving,
  53. and storing MIDI data.  It has many uses:
  54.  
  55.     o    Learning about MIDI.
  56.  
  57.     o    Discovering your instrument's system exclusive data
  58.         format.
  59.  
  60.     o    Testing your instrument's MIDI capabilities.
  61.  
  62.     o    Acting as a patch librarian.  (VERY VERY basic, though.)
  63.  
  64.     o    Helping you write MIDI software.
  65.  
  66.     Essentially, MP is a "translator" program that understands 3
  67. data formats and translates between any pair:
  68.  
  69.         (1)    English text
  70.         (2)    Binary data
  71.         (3)    MIDI data
  72.  
  73. Formats (2) and (3) are really the same, but (2) is stored in files on your
  74. Amiga, and (3) is transmitted via your MIDI interface.
  75.  
  76.     
  77. WHAT IS MP NOT?
  78.  
  79.     MP is not a sequencer.  It does not store any kind of timing
  80. information.  MP simply sends and receives bytes in the order they are
  81. given.
  82.  
  83.     
  84. MP CONCEPTS
  85.  
  86.     Like I said, MP translates between text, binary data, and MIDI
  87. data.  All you need to do is:
  88.  
  89.     (1)    Choose a format for the input.
  90.     (2)    Choose a format for the output.
  91.         (The input and output formats can be the same if you like.)
  92.     (3)    Run MP.
  93.  
  94. For example, you can ask MP to use "text" as input and "MIDI" as output.
  95. This lets you type text in a very easy-to-learn language, and it immediately
  96. gets sent out as MIDI data.  If you reverse these choices (input=MIDI,
  97. output=text), you can watch MIDI data appear on your screen in a simple
  98. but readable format.
  99.  
  100.     Another use would be to use "MIDI" as input and "binary" as output.
  101. This lets you press keys and buttons on your instrument, and have all
  102. the data stored in binary format in an Amiga file.  To send the data back
  103. to the instrument, just use "binary" for input and "MIDI" for output!
  104.  
  105.     Yet another use is for MP to translate between binary data and
  106. readable text.  This can help you to understand the contents of a binary
  107. MIDI file, or to create binary MIDI files by typing simple text commands.
  108. (Note:  this facility will work with ANY binary files, not just those
  109. containing MIDI data.)
  110.  
  111.     You can also ask MP to translate from one format to the same
  112. format!  For example, it can read MIDI data and "echo" it back to the
  113. sending instrument (translating MIDI to MIDI), copy binary files (translating
  114. binary to binary), or let you practice with its text language (text to
  115. text).
  116.  
  117.     
  118. A FIRST EXERCISE
  119.  
  120.     Let's ask MP to translate from MIDI into text.  Make sure your
  121. MIDI synthesizer is hooked up properly to your Amiga.  Type:
  122.  
  123.         1>  mp  -im  -ot
  124.  
  125. (This asks MP to use MIDI input (-im) and text output (-ot).)
  126.  
  127.     Now go to your instrument and play notes, press buttons, turn
  128. dials, etc.  You should see things appearing on your Amiga screen!  To
  129. exit the program, type ^C (control-C) on the Amiga.
  130.  
  131.  
  132. FORMAL USAGE INSTRUCTIONS FOR MP
  133.  
  134.     MP's syntax is:
  135.  
  136.         1>  mp  -i{tbm}  -o{tbm}  [-g infile]  [-p outfile]
  137.  
  138. The flags "-i" and "-o" are mandatory (they MUST appear, in any order).
  139. The flag "-i" represents input, and "-o" represents output.  You also
  140. must fill in the "[choice]" specifying text, binary, or MIDI.  The syntax
  141. is:
  142.  
  143.         t    Text
  144.         b    Binary data
  145.         m    MIDI
  146.  
  147. For example, to read text from the keyboard and send to MIDI:
  148.  
  149.         1>  mp -it -om
  150.  
  151. To read MIDI data and convert it to text:
  152.  
  153.         1>  mp -ot -im
  154.  
  155. If you would like to GET your input from a file (not the keyboard), you may
  156. specify a file name with the -g option.  Similarly, the -p option allows
  157. you to PUT the output into a file (rather than the screen).  The -g and -p
  158. options have no meaning, obviously, if your input and output are MIDI,
  159. respectively.
  160.  
  161.     
  162. THE INPUT TEXT LANGUAGE
  163.  
  164.     If you do not already know what MIDI code looks like (for
  165. example, hexadecimal 90 means "Note On, MIDI channel 0"), then this
  166. section might not be useful to you yet.  But feel free to try!
  167.  
  168.     MP understands many different kinds of text input.  To use the
  169. text input feature, you must learn a very simple syntax.  If you are a
  170. C programmer, you will recognize some of this language and feel right
  171. at home.  (Don't worry... you don't have to be a C programmer to use MP!
  172. It will take a little practice, though.)
  173.  
  174.     MP understands NUMBERS (between 0 and 255) in:
  175.  
  176.     -    Base 10 (decimal or "normal" numbers)
  177.         Just type the number normally.
  178.         Example:    123
  179.  
  180.     -    Base 8 (octal)
  181.         Precede the number with a zero.
  182.         Example:    024
  183.  
  184.     -    Base 16 (hexadecimal)
  185.         Precede the number with an "H" or the symbol "0x".
  186.         If the number begins with A through F, you can skip the
  187.          above symbols.
  188.         Examples:    0x2A     H44    F7
  189.  
  190.     -    Base 2 (binary)
  191.         Precede the number with a "#".
  192.         Example:    #10010110
  193.  
  194.     All special symbols (such as "H", "0x", and the hexadecimal numbers
  195.     from A...F) are case-insensitive.  That means capital and small
  196.     letters are equivalent.
  197.  
  198. MP understands CHARACTERS as:
  199.  
  200.     -    Individual characters.
  201.         Enclose in single quotes, like 'x'.
  202.  
  203.     -    Character strings.
  204.         Enclose in double quotes, like "this is a string".
  205.  
  206.     C special characters (like '\n') are recognized both as individual
  207.     characters and in strings.
  208.  
  209.     If you type a RETURN in the middle of a string, it is interpreted
  210.     as a space character.  (If you want a real newline character, use
  211.     \n.)  If a string is too long to fit on your screen, break it into
  212.     2 strings (or more), each surrounded by double-quotes.
  213.  
  214.  
  215.     All of these numbers/characters are automatically converted into
  216. bytes.  As a result, you cannot specify a number with value greater than 
  217. 255 (base 10) or less than 0.  If you do, you will get an error message.
  218.  
  219.     MP also has a "comment" symbol.  This lets you type text that is
  220. ignored by MP.  Any text following a semicolon (";") is ignored until
  221. the end of the line.  (This is just like the Amiga CLI comment symbol.)
  222. (Of course, this does not occur if the semicolon is part of a character
  223. constant or string.)
  224.     Why is a comment symbol useful?  You can put text language commands
  225. in a file and send it to your MIDI instrument.  Comments allow you to 
  226. document the meaning of the contents of the file.  For example:
  227.  
  228.         ; Send a C major chord on MIDI channel 0
  229.         0x90 60 127 64 127 67 127
  230.  
  231.  
  232.     EVERY INDIVIDUAL NUMBER/CHARACTER/STRING/COMMENT THAT YOU TYPE
  233. MUST BE SEPARATED FROM ITS NEIGHBORS BY WHITESPACE (blanks, tabs, newlines).
  234. Yes, even comments.  This may change in a later version of the program.
  235.  
  236.  
  237. PRACTICING WITH THE TEXT LANGUAGE
  238.  
  239.     Type the command:
  240.  
  241.         1>  mp  -it  -ot
  242.  
  243. This tells MP to translate from text into text, totally bypassing MIDI.
  244. As you type in the text language, you will see your data interpreted by
  245. MP.  To end MP, type control-C (^C).
  246.  
  247.     When you feel comfortable with the text language, try sending some
  248. data to your synthesizer.  Type:
  249.  
  250.         1>  mp  -it  -om
  251.  
  252. Here is some data:
  253.  
  254.         H90 60 100
  255.  
  256. This tells the instrument to play Middle C (note 60) at volume (velocity)
  257. 100, assuming the instrument is on MIDI channel 0.  To turn off the note:
  258.  
  259.         H80 60 0
  260.  
  261. To end MP, type control-C (^C).
  262.  
  263.     
  264. USING THE FILE INPUT/OUTPUT OPTIONS TO MAKE NEW WINDOWS
  265.  
  266.     On the Amiga, you can specify a NEW WINDOW as a file, rather than
  267. an actual disk file.  The syntax is found in your AmigaDOS manual, under
  268. the NewCLI or NewShell command.  For example, to print your output in
  269. a 640x100 window, positioned at screen location (20,25), with window name
  270. "MP-IN", you would use:
  271.  
  272.         1>  mp ... -g "CON:20/25/640/100/MP-IN" ...
  273.  
  274. Do similarly for output windows, but use -p instead of -g.
  275.  
  276.  
  277. USING REDIRECTION
  278.  
  279.     You can use the CLI's INPUT REDIRECTION symbol to get input from a
  280. file instead of from the keyboard.  See your AmigaDOS manual for more details.
  281. The syntax is:
  282.             < filename
  283.     
  284. and it must appear immediately after the command name (MP).  For example:
  285.  
  286.         1>  mp  < infile  -it -om
  287.  
  288. to send text data (translated to MIDI) from the file "infile" to the 
  289. MIDI instrument.
  290.  
  291.     Some sample input files are included with this program.
  292.  
  293.     You may also use the CLI's OUTPUT REDIRECTION symbol to send output 
  294. to a file instead of to the screen.  See your AmigaDOS manual for more 
  295. details.  The syntax is:
  296.  
  297.             > filename
  298.  
  299. and it must appear immediately after the command name (MP).  For example:
  300.  
  301.         1>  mp  > outfile  -im -ot
  302.  
  303. to capture MIDI data (translated to text) into the file "outfile".
  304.  
  305.         
  306. TRANSLATING BINARY DATA TO/FROM TEXT
  307.  
  308.     Suppose you have a binary file that you want to translate to
  309. text.  (It does not even have to be a MIDI data file!!)  Just type:
  310.  
  311.         1>  mp  < binaryFile  -ib -ot
  312.  
  313. If you prefer to save your text results in a file, type:
  314.  
  315.         1>  mp  < binaryFile > textFile  -ib -ot
  316.  
  317.  
  318. USING AN ALTERNATE MIDI INTERFACE
  319.  
  320.     By default, the MP assumes that your MIDI interface
  321. is connected to your Amiga's internal serial port.  If this is
  322. not the case, you can override this by using an Amiga environment
  323. variable and the SetEnv command.  (See your Amiga documentation for
  324. full details about SetEnv.)
  325.  
  326.     The name of the environment variable is MP_MIDI_DEVICE, and its
  327. value must be of the following format:
  328.  
  329.     1)    The name of the MIDI device driver, located in the
  330.         DEVS: directory of your system disk.  It should be
  331.         something like "midi.device" or "serial2.device".
  332.  
  333.     2)    One colon character (':').
  334.  
  335.     3)    The unit number for the device.  If you have only
  336.         1 port using the device, your unit number is probably
  337.         zero.
  338.  
  339.     Example:    midi.device:2
  340.  
  341.     Suppose you want to set up MP to use unit 3 the device
  342. "AltMidi.device".  Type:
  343.  
  344.         1>  SetEnv MP_MIDI_DEVICE AltMidi.device:3
  345.  
  346. To check that the value was set correctly, type:
  347.  
  348.         1>  GetEnv MP_MIDI_DEVICE
  349.  
  350.     If you are using a MIDI interface attached to your internal
  351. serial, port, YOU MAY IGNORE ALL OF THIS STUFF.  By default, MP uses
  352. unit 0 of the device "serial.device".
  353.  
  354.     I cannot guarantee that MP will work with whatever alternate device
  355. driver you choose.  But I have tested the environment variable mechanism
  356. itself, and it works.
  357.  
  358.     
  359. PROBLEMS YOU MAY HAVE WITH MP
  360.  
  361.     I have tested these programs fairly well on my own equipment:
  362. Amiga 1000, Golden Hawk MIDI Gold interface, and an Oberheim Matrix-12.
  363. If the program doesn't work for you, first check:
  364.  
  365. (?)    Is the file "serial.device" in the DEVS: directory of your system
  366.     disk?  If not, MP will refuse to run, and you will see an error
  367.     message like one of these:
  368.  
  369.         Cannot create a message port.
  370.         Cannot create an extended I/O request.
  371.         Cannot open the MIDI device.
  372.         Cannot set the serial parameters.
  373.  
  374.     Boot your Amiga with an original Workbench disk and try again.
  375.  
  376. (?)    Are you running a version of the Amiga operating system that is
  377.     older than 1.3?  MP should work with some or all earlier
  378.     versions, but I have not tested this.
  379.  
  380. (?)    Are your MIDI cables connected properly?  Remember that MIDI OUT
  381.     must always be connected to MIDI IN, and vice-versa.
  382.  
  383.         SYNTHESIZER            COMPUTER
  384.         -----------            --------
  385.         MIDI IN     <------------------->    MIDI OUT
  386.         MIDI OUT <------------------->    MIDI IN
  387.  
  388. (?)    Are you using the program correctly?  Double-check the instructions
  389.     above.
  390.  
  391. (?)    Are you running another program that uses the serial port, such as
  392.     a communications program, printing program, or another MIDI program?
  393.     If so, this other program may be using the serial port.  (MP
  394.     uses the serial port in "shared" mode so it doesn't hog the
  395.     serial port.) Exit your other programs and try again.  If it
  396.     still doesn't work, reboot to make sure that your other programs
  397.     didn't accidently leave the serial port "locked".
  398.  
  399.     Some programs allow you to "release" their hold on the serial port
  400.     without exiting.  (Example:  Music-X.)  This may be enough to allow
  401.     MP to run.
  402.  
  403.     If you run MP with the "-im" format (input from MIDI), you cannot
  404.     run MP a second time simultaneously.  This is because the Amiga
  405.     serial port initialization routines will fail if there is another
  406.     program reading the serial port.
  407.  
  408. (?)    Are you running any other programs simultaneously with MP?
  409.     It is possible that a badly-written program could
  410.     interfere with the operation of other programs.  Boot your Amiga
  411.     with an original Workbench disk and try again.
  412.  
  413. (?)    Is your synthesizer turned on?  Seriously.  This has happened
  414.     to me.  :-)
  415.  
  416. If you are doing everything right, then there may be a bug in the
  417. program.  For example, MP should NEVER crash your Amiga.  If you
  418. believe that there is a bug, please contact me (electronic mail is
  419. preferred).  But first, try to reproduce the bug consistently.  Can
  420. you find a particular set of actions, keystrokes, etc., that ALWAYS
  421. make the program crash?  If you can, then I will be able to find the
  422. bug faster. 
  423.  
  424.         
  425. NOTES ABOUT THE SOURCE CODE
  426.  
  427.     The file "text.c" contains a good example of using a finite
  428. automaton to read the text language and translate it into bytes.  The
  429. code is fairly robust and easy to modify.  For example, I was able to
  430. add "binary number" support in about 3 minutes, and "string" support in
  431. about 10 minutes.
  432.     The theory of finite automata is extremely important for programmers,
  433. but it can seem very "theoretical" at first.  Believe me, it helps you
  434. write correct programs that are easy to modify later.
  435.  
  436.     The file "serial.c" contains serial port code that you are welcome
  437. to use.  The function "DoTheIO()" implements asynchronous I/O in a very
  438. multitasking-friendly way.  The function "FastSerialRead()" is patterned
  439. after Commodore's recommended method for reading the serial port quickly.
  440. The method is documented in the AMIGA ROM KERNEL REFERENCE MANUAL:  
  441. LIBRARIES AND DEVICES, for version 1.3 of the Amiga Operating System.
  442.  
  443.     The file "main.c" contains examples of using pointers to functions
  444. and pointers-to-pointers to functions.  (The functions themselves are
  445. defined in "iofunctions.c".)
  446.  
  447.     The file "getopt.c" contains my version of the powerful and useful
  448. UNIX "getopt()" function.  This gives the programmer a standard interface
  449. for reading command-line options (flags) from the user.  I have used this
  450. file (unchanged) in a dozen programs.
  451.  
  452.     The "Makefile" is pretty generic.  If you want to add a new
  453. file to the program, just append its name (and its object file's name)
  454. to the SRC and OBJ macros, and type "make".
  455.  
  456.  
  457. NOTES ABOUT THE PROGRAM'S INTERNALS (AND LIMITATIONS)
  458.  
  459.     MP uses a very inefficient method for sending MIDI data and
  460. reading/writing files:  one byte at a time.  This could definitely be
  461. made faster, but takes some cleverness (and some internal buffering).
  462. MP does read MIDI data very efficiently, though.
  463.  
  464.     This limitation is due to the byte-oriented nature of this program.
  465. Also, when the user is typing text, he/she wants immediate feedback from
  466. a MIDI device.  I'm sure there is a better way to do this than my method.
  467.  
  468.     I did not build this program for large data transfers.  It is
  469. mainly for transmitting small amounts of data for diagnostic purposes.
  470. This is why I have released the program before its I/O routines are
  471. improved.
  472.